﻿using IENMService.Model;
using IENMService.Service;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace IENMService.Controllers
{
    /// <summary>
    /// 上海护加加智慧护理接口服务
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class IENMController : ControllerBase
    {
        #region 内部方法
        /// <summary>
        /// 日志
        /// </summary>
        private readonly ILogger<IENMController> _logger;

        /// <summary>
        /// 接口服务
        /// </summary>
        private readonly IENMInterface _service;

        /// <summary>
        /// 构造函数注入
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="service"></param>
        public IENMController(ILogger<IENMController> logger, IENMInterface service)
        {
            //日志
            _logger = logger;

            //接口服务
            _service = service;

        }
        #endregion


        /// <summary>
        /// 4.1.1.1 获取科室列表
        /// </summary>
        /// <param name="updateTime">数据更新时间</param>
        /// <param name="pageNum">页码</param>
        /// <param name="pageSize">每页显示条数</param>
        /// <returns></returns>
        [HttpGet("getDepts")]
        public async Task<ActionResult<ResponseList<Dept>>> getDepts(DateTime updateTime, int pageNum, int pageSize)
        {
            var result = new ResponseList<Dept>();

            try
            {
                var data = await _service.getDepts(updateTime, pageNum, pageSize);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return result;
        }

        /// <summary>
        /// 4.1.1.2 获取科室类型
        /// </summary>
        /// <param name="updateTime">数据更新时间</param>
        /// <param name="pageNum">页码</param>
        /// <param name="pageSize">每页显示条数</param>
        /// <returns></returns>
        [HttpGet("getDeptTypes")]
        public async Task<ActionResult<ResponseList<DeptType>>> getDeptTypes(DateTime updateTime, int pageNum, int pageSize)
        {
            var result = new ResponseList<DeptType>();

            try
            {
                var data = await _service.getDeptTypes(updateTime, pageNum, pageSize);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

        /// <summary>
        /// 4.1.1.3 获取科室与病区关联关系
        /// </summary>
        /// <param name="updateTime">数据更新时间</param>
        /// <param name="pageNum">页码</param>
        /// <param name="pageSize">每页显示条数</param>
        /// <returns></returns>
        [HttpGet("getDeptWardRelation")]
        public async Task<ActionResult<ResponseList<DeptWardRelation>>> getDeptWardRelation(DateTime updateTime, int pageNum, int pageSize)
        {
            var result = new ResponseList<DeptWardRelation>();

            try
            {
                var data = await _service.getDeptWardRelation(updateTime, pageNum, pageSize);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

        /// <summary>
        /// 4.1.1.4 获取职工与科室关系
        /// </summary>
        /// <param name="updateTime">数据更新时间</param>
        /// <param name="pageNum">页码</param>
        /// <param name="pageSize">每页显示条数</param>
        /// <returns></returns>
        [HttpGet("getUsersDept")]
        public async Task<ActionResult<ResponseList<UsersDept>>> getUsersDept(DateTime updateTime, int pageNum, int pageSize)
        {
            var result = new ResponseList<UsersDept>();

            try
            {
                var data = await _service.getUsersDept(updateTime, pageNum, pageSize);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

        /// <summary>
        /// 4.1.1.5 获取职工信息
        /// </summary>
        /// <param name="updateTime">数据更新时间</param>
        /// <param name="pageNum">页码</param>
        /// <param name="pageSize">每页显示条数</param>
        /// <returns></returns>
        [HttpGet("getUsers")]
        public async Task<ActionResult<ResponseList<User>>> getUsers(DateTime updateTime, int pageNum, int pageSize)
        {
            var result = new ResponseList<User>();

            try
            {
                var data = await _service.getUsers(updateTime, pageNum, pageSize);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

        /// <summary>
        /// 4.1.1.6 获取职工与角色关系信息
        /// </summary>
        /// <param name="updateTime">数据更新时间</param>
        /// <param name="pageNum">页码</param>
        /// <param name="pageSize">每页显示条数</param>
        /// <returns></returns>
        [HttpGet("getUserRoles")]
        public async Task<ActionResult<ResponseList<UserRoles>>> getUserRoles(DateTime updateTime, int pageNum, int pageSize)
        {
            var result = new ResponseList<UserRoles>();

            try
            {
                var data = await _service.getUserRoles(updateTime, pageNum, pageSize);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

        /// <summary>
        /// 4.1.1.7 获取床位列表信息
        /// </summary>
        /// <param name="deptCode">科室编号</param>
        /// <param name="updateTime">数据更新时间</param>
        /// <param name="pageNum">页码</param>
        /// <param name="pageSize">每页显示条数</param>
        /// <returns></returns>
        [HttpGet("getDeptBeds")]
        public async Task<ActionResult<ResponseList<DeptBeds>>> getDeptBeds(string deptCode, DateTime updateTime, int pageNum, int pageSize)
        {
            var result = new ResponseList<DeptBeds>();

            try
            {
                var data = await _service.getDeptBeds(deptCode,updateTime, pageNum, pageSize);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

        /// <summary>
        /// 4.1.1.8 获取患者信息
        /// </summary>
        /// <param name="patientId">患者唯一号</param>
        /// <param name="inpNo">住院号</param>
        /// <param name="visitId">入院次数</param>
        /// <param name="inHospital">0：获取全部，1：只获取在院</param>
        /// <param name="deptCode">科室编号</param>
        /// <param name="admissiontime">入院时间</param>
        /// <param name="updateTime">更新时间</param>
        /// <param name="pageNum">页码</param>
        /// <param name="pageSize">每页条数</param>
        /// <returns></returns>
        [HttpGet("getPatients")]
        public async Task<ActionResult<ResponseList<Patient>>> getPatients(string? patientId, string? inpNo, int? visitId, string? inHospital, string? deptCode, DateTime? admissiontime, DateTime? updateTime, int pageNum, int pageSize)
        {
            var result = new ResponseList<Patient>();

            try
            {
                var data = await _service.getPatients(patientId, inpNo, visitId, inHospital, deptCode, admissiontime, updateTime, pageNum, pageSize);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

        /// <summary>
        /// 4.1.1.9 获取患者转科记录信息
        /// </summary>
        /// <param name="PATIENT_ID">患者唯一编号</param>
        /// <param name="INP_NO">住院号</param>
        /// <param name="VISIT_ID">住院次数</param>
        /// <param name="START_TIME">转入或转出开始时间</param>
        /// <param name="END_TIME">转入或转出结束时间</param>
        /// <param name="UPDATE_TIME">数据更新时间</param>
        /// <param name="PAGENUM">页码</param>
        /// <param name="PAGESIZE">每页显示条数</param>
        /// <returns></returns>
        [HttpGet("getTransferRecord")]
        public async Task<ActionResult<ResponseList<TransferRecord>>> getTransferRecord(string? PATIENT_ID, string? INP_NO, string? VISIT_ID, DateTime? START_TIME, DateTime? END_TIME, DateTime? UPDATE_TIME, int PAGENUM, int PAGESIZE)
        {
            var result = new ResponseList<TransferRecord>();

            try
            {
                var data = await _service.getTransferRecord(PATIENT_ID, INP_NO, VISIT_ID, START_TIME, END_TIME, UPDATE_TIME, PAGENUM, PAGESIZE);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

        /// <summary>
        /// 4.1.1.10 获取患者出院撤回记录
        /// </summary>
        /// <param name="DEPT_CODE">科室编号</param>
        /// <param name="START_TIME">开始时间</param>
        /// <param name="END_TIME">结束时间</param>
        /// <param name="UPDATE_TIME">数据更新时间</param>
        /// <param name="PAGENUM">页码</param>
        /// <param name="PAGESIZE">每页条数</param>
        /// <returns></returns>
        [HttpGet("getPatientLeaveRevoke")]
        public async Task<ActionResult<ResponseList<PatientLeaveRevoke>>> getPatientLeaveRevoke(string? DEPT_CODE, DateTime? START_TIME, DateTime? END_TIME, DateTime UPDATE_TIME, int PAGENUM, int PAGESIZE)
        {
            var result = new ResponseList<PatientLeaveRevoke>();

            try
            {
                var data = await _service.getPatientLeaveRevoke(DEPT_CODE, START_TIME, END_TIME, UPDATE_TIME, PAGENUM, PAGESIZE);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

        /// <summary>
        /// 4.1.1.11 获取医嘱用法信息
        /// </summary>
        /// <param name="UPDATE_TIME">数据更新时间</param>
        /// <param name="PAGENUM">页码</param>
        /// <param name="PAGESIZE">每页条数</param>
        /// <returns></returns>
        [HttpGet("getDoctorAdviceUsage")]
        public async Task<ActionResult<ResponseList<DoctorAdviceUsage>>> getDoctorAdviceUsage(DateTime UPDATE_TIME, int PAGENUM, int PAGESIZE)
        {
            var result = new ResponseList<DoctorAdviceUsage>();

            try
            {
                var data = await _service.getDoctorAdviceUsage(UPDATE_TIME, PAGENUM, PAGESIZE);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

        /// <summary>
        /// 4.1.1.12 获取医嘱类型信息
        /// </summary>
        /// <param name="UPDATE_TIME">数据更新时间</param>
        /// <returns></returns>
        [HttpGet("getDoctorAdviceType")]
        public async Task<ActionResult<ResponseList<DoctorAdviceType>>> getDoctorAdviceType(DateTime UPDATE_TIME)
        {
            var result = new ResponseList<DoctorAdviceType>();

            try
            {
                var data = await _service.getDoctorAdviceType(UPDATE_TIME);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

        /// <summary>
        /// 4.1.1.13 获取医嘱类别信息
        /// </summary>
        /// <param name="UPDATE_TIME">数据更新时间</param>
        /// <returns></returns>
        [HttpGet("getDoctorAdviceCategory")]
        public async Task<ActionResult<ResponseList<DoctorAdviceCategory>>> getDoctorAdviceCategory(DateTime UPDATE_TIME)
        {
            var result = new ResponseList<DoctorAdviceCategory>();

            try
            {
                var data = await _service.getDoctorAdviceCategory(UPDATE_TIME);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

        /// <summary>
        /// 4.1.1.14 获取医嘱状态信息
        /// </summary>
        /// <param name="UPDATE_TIME">数据更新时间</param>
        /// <returns></returns>
        [HttpGet("getDoctorAdviceStatus")]
        public async Task<ActionResult<ResponseList<DoctorAdviceStatus>>> getDoctorAdviceStatus(DateTime UPDATE_TIME)
        {
            var result = new ResponseList<DoctorAdviceStatus>();

            try
            {
                var data = await _service.getDoctorAdviceStatus(UPDATE_TIME);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

        /// <summary>
        /// 4.1.1.15 获取医嘱频次信息
        /// </summary>
        /// <param name="UPDATE_TIME">数据更新时间</param>
        /// <returns></returns>
        [HttpGet("getDoctorAdviceFrequency")]
        public async Task<ActionResult<ResponseList<DoctorAdviceFrequency>>> getDoctorAdviceFrequency(DateTime UPDATE_TIME)
        {
            var result = new ResponseList<DoctorAdviceFrequency>();

            try
            {
                var data = await _service.getDoctorAdviceFrequency(UPDATE_TIME);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

        /// <summary>
        /// 4.1.1.16 获取医嘱详细信息
        /// </summary>
        /// <param name="DOCTOR_ADVICE_ID">医嘱号，支持多个用逗号拼接</param>
        /// <param name="INP_NO">住院号</param>
        /// <param name="VISIT_ID">入院次数</param>
        /// <param name="ORDERING_DEPT_CODE">开单科室编号</param>
        /// <param name="STARTTIME_FROM">医嘱开始时间（检索开始时间）</param>
        /// <param name="STARTTIME_TO">医嘱开始时间（检索结束时间）</param>
        /// <param name="ISENABLE">是否启用，1 是，0 否,默认全部</param>
        /// <param name="ISSTOP">是否停止，1 是，0 否,默认全部</param>
        /// <param name="UPDATE_TIME">数据更新时间</param>
        /// <param name="PAGENUM">页码</param>
        /// <param name="PAGESIZE">每页显示条数</param>
        /// <returns></returns>
        [HttpGet("getDoctorAdvice")]
        public async Task<ActionResult<ResponseList<DoctorAdvice>>> getDoctorAdvice(string? DOCTOR_ADVICE_ID, string? INP_NO, string? VISIT_ID, string? ORDERING_DEPT_CODE, DateTime? STARTTIME_FROM, DateTime? STARTTIME_TO, int? ISENABLE, int? ISSTOP, DateTime? UPDATE_TIME, int PAGENUM, int PAGESIZE)
        {
            var result = new ResponseList<DoctorAdvice>();

            try
            {
                var data = await _service.getDoctorAdvice(DOCTOR_ADVICE_ID, INP_NO, VISIT_ID, ORDERING_DEPT_CODE, STARTTIME_FROM, STARTTIME_TO, ISENABLE, ISSTOP, UPDATE_TIME, PAGENUM, PAGESIZE);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

        /// <summary>
        /// 4.1.1.17 获取疾病名称信息
        /// </summary>
        /// <param name="UPDATE_TIME">数据更新时间</param>
        /// <param name="PAGENUM">页码</param>
        /// <param name="PAGESIZE">每页显示条数</param>
        /// <returns></returns>
        [HttpGet("getICD10")]
        public async Task<ActionResult<ResponseList<ICD10>>> getICD10(DateTime UPDATE_TIME, int PAGENUM, int PAGESIZE)
        {
            var result = new ResponseList<ICD10>();

            try
            {
                var data = await _service.getICD10(UPDATE_TIME, PAGENUM, PAGESIZE);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

        /// <summary>
        /// 4.1.1.18 获取检验申请信息
        /// </summary>
        /// <param name="APPLY_DEPT_CODE">申请科室编号</param>
        /// <param name="APPLY_DATE_FROM">检验申请开始时间</param>
        /// <param name="APPLY_DATE_TO">检验申请结束时间</param>
        /// <param name="UPDATE_TIME">数据更新时间</param>
        /// <param name="PAGENUM">页码</param>
        /// <param name="PAGESIZE">每页条数</param>
        /// <returns></returns>
        [HttpGet("getExamine")]
        public async Task<ActionResult<ResponseList<Examine>>> getExamine(string? APPLY_DEPT_CODE, DateTime? APPLY_DATE_FROM, DateTime? APPLY_DATE_TO, DateTime UPDATE_TIME, int PAGENUM, int PAGESIZE)
        {
            var result = new ResponseList<Examine>();

            try
            {
                var data = await _service.getExamine(APPLY_DEPT_CODE, APPLY_DATE_FROM, APPLY_DATE_TO, UPDATE_TIME, PAGENUM, PAGESIZE);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

        /// <summary>
        /// 4.1.1.19 获取检验结果信息
        /// </summary>
        /// <param name="APPLY_DEPT_CODE">病区代码</param>
        /// <param name="APPLY_IDS">申请单号，多个以逗号分隔</param>
        /// <param name="RESULT_DATE_TIME_FROM">检验结果开始时间</param>
        /// <param name="RESULT_DATE_TIME_TO">检验结果结束时间</param>
        /// <param name="UPDATE_TIME">数据更新时间</param>
        /// <param name="PAGENUM">页码</param>
        /// <param name="PAGESIZE">每页显示条数</param>
        /// <returns></returns>
        [HttpGet("getExamineResult")]
        public async Task<ActionResult<ResponseList<ExamineResult>>> getExamineResult(string? APPLY_DEPT_CODE, string? APPLY_IDS, DateTime? RESULT_DATE_TIME_FROM, DateTime? RESULT_DATE_TIME_TO, DateTime UPDATE_TIME, int PAGENUM, int PAGESIZE)
        {
            var result = new ResponseList<ExamineResult>();

            try
            {
                var data = await _service.getExamineResult(APPLY_DEPT_CODE,APPLY_IDS, RESULT_DATE_TIME_FROM, RESULT_DATE_TIME_TO, UPDATE_TIME, PAGENUM, PAGESIZE);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

        /// <summary>
        /// 4.1.1.20 获取检查申请和报告信息
        /// </summary>
        /// <param name="APPLY_DEPT_CODE">开单科室编号</param>
        /// <param name="APPLY_DATE_FROM">检查申请开始时间</param>
        /// <param name="APPLY_DATE_TO">检查申请结束时间</param>
        /// <param name="INP_NO">住院号</param>
        /// <param name="VISIT_ID">住院次数</param>
        /// <param name="APPLY_ID">申请单编号</param>
        /// <param name="PAGENUM">页码</param>
        /// <param name="PAGESIZE">每页显示条数</param>
        /// <returns></returns>
        [HttpGet("getInspect")]
        public async Task<ActionResult<ResponseList<Inspect>>> getInspect(string? APPLY_DEPT_CODE, DateTime? APPLY_DATE_FROM, DateTime? APPLY_DATE_TO, string? INP_NO, int? VISIT_ID, string? APPLY_ID, int PAGENUM, int PAGESIZE)
        {
            var result = new ResponseList<Inspect>();

            try
            {
                var data = await _service.getInspect(APPLY_DEPT_CODE, APPLY_DATE_FROM, APPLY_DATE_TO, INP_NO, VISIT_ID, APPLY_ID, PAGENUM, PAGESIZE);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

        /// <summary>
        /// 4.1.1.21 获取临床诊疗项目
        /// </summary>
        /// <param name="UPDATE_TIME">数据更新时间</param>
        /// <param name="PAGENUM">页码</param>
        /// <param name="PAGESIZE">每页显示条数</param>
        /// <returns></returns>
        [HttpGet("getClinicalProject")]
        public async Task<ActionResult<ResponseList<ClinicalProject>>> getClinicalProject(DateTime UPDATE_TIME, int PAGENUM, int PAGESIZE)
        {
            var result = new ResponseList<ClinicalProject>();

            try
            {
                var data = await _service.getClinicalProject(UPDATE_TIME, PAGENUM, PAGESIZE);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

        /// <summary>
        /// 4.1.1.22 获取新生儿信息
        /// </summary>
        /// <param name="MOTHER_INP_NO">母亲住院号，多个以逗号分隔</param>
        /// <param name="DEPT_CODE">科室编号</param>
        /// <param name="UPDATE_TIME">数据更新时间</param>
        /// <param name="PAGENUM">页码</param>
        /// <param name="PAGESIZE">每页显示条数</param>
        /// <returns></returns>
        [HttpGet("getBabies")]
        public async Task<ActionResult<ResponseList<Baby>>> getBabies(string? MOTHER_INP_NO, string? DEPT_CODE, DateTime UPDATE_TIME, int PAGENUM, int PAGESIZE)
        {
            var result = new ResponseList<Baby>();

            try
            {
                var data = await _service.getBabies(MOTHER_INP_NO, DEPT_CODE, UPDATE_TIME, PAGENUM, PAGESIZE);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

        /// <summary>
        /// 4.1.1.23 获取药品目录
        /// </summary>
        /// <param name="UPDATE_TIME">数据更新时间</param>
        /// <param name="PAGENUM">页码</param>
        /// <param name="PAGESIZE">每页显示条数</param>
        /// <returns></returns>
        [HttpGet("getDrugDictionary")]
        public async Task<ActionResult<ResponseList<DrugDictionary>>> getDrugDictionary(DateTime UPDATE_TIME, int PAGENUM, int PAGESIZE)
        {
            var result = new ResponseList<DrugDictionary>();

            try
            {
                var data = await _service.getDrugDictionary(UPDATE_TIME, PAGENUM, PAGESIZE);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

        /// <summary>
        /// 4.1.1.24 获取换床信息
        /// </summary>
        /// <param name="DEPT_CODE">科室编号</param>
        /// <param name="CHANGE_TIME_FROM">换床开始时间</param>
        /// <param name="CHANGE_TIME_TO">换床结束时间</param>
        /// <param name="INP_NO">住院号</param>
        /// <param name="VISIT_ID">入院次数</param>
        /// <param name="UPDATE_TIME">数据更新时间</param>
        /// <param name="PAGENUM">页码</param>
        /// <param name="PAGESIZE">每页显示条数</param>
        /// <returns></returns>
        [HttpGet("getTodayChangeBeds")]
        public async Task<ActionResult<ResponseList<ChangeBeds>>> getTodayChangeBeds(string? DEPT_CODE, DateTime? CHANGE_TIME_FROM, DateTime? CHANGE_TIME_TO, string? INP_NO, int? VISIT_ID, DateTime UPDATE_TIME, int PAGENUM, int PAGESIZE)
        {
            var result = new ResponseList<ChangeBeds>();

            try
            {
                var data = await _service.getTodayChangeBeds(DEPT_CODE, CHANGE_TIME_FROM, CHANGE_TIME_TO, INP_NO, VISIT_ID, UPDATE_TIME, PAGENUM, PAGESIZE);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

        /// <summary>
        /// 4.1.1.25 获取患者撤销入科记录
        /// </summary>
        /// <param name="UPDATE_TIME">数据更新时间</param>
        /// <param name="PAGENUM">页码</param>
        /// <param name="PAGESIZE">每页显示条数</param>
        /// <returns></returns>
        [HttpGet("getOutWardRecord")]
        public async Task<ActionResult<ResponseList<OutWardRecord>>> getOutWardRecord(DateTime UPDATE_TIME, int PAGENUM, int PAGESIZE)
        {
            var result = new ResponseList<OutWardRecord>();

            try
            {
                var data = await _service.getOutWardRecord(UPDATE_TIME, PAGENUM, PAGESIZE);

                result.code = 200;
                result.msg = "调用接口成功";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }



        /// <summary>
        /// 4.1.2.1. 人员调科:把护理人员及该护理人员在 HIS 的权限调到另一个科室，支持同时调到多个科室
        /// </summary>
        /// <param name="NURSE_CODE">护理人员编号</param>
        /// <param name="TRANFROM_DEPT_CODE">调出科室编号，可以为多个，以逗号隔开</param>
        /// <param name="TRANTO_DEPT_CODE">调入科室编号，可以为多个，以逗号隔开</param>
        /// <param name="OPERATOR">操作人员</param>
        /// <returns></returns>
        [HttpPost("transferNurse")]
        public async Task<ActionResult> transferNurse(string NURSE_CODE, string TRANFROM_DEPT_CODE, string TRANTO_DEPT_CODE, string OPERATOR)
        {
            var result = new Response<Responsedata>();

            try
            {
                var data = await _service.transferNurse(NURSE_CODE, TRANFROM_DEPT_CODE, TRANTO_DEPT_CODE, OPERATOR);

                result.code = 200;
                result.msg = "success";
                result.data = null;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }


        /// <summary>
        /// 4.1.2.2. 离职/退休/注销:护理人员在离职、退休或账号注销时使用
        /// </summary>
        /// <param name="NURSE_CODE">护理人员编号</param>
        /// <param name="TYPE">1：离职，2：退休，3：注销</param>
        /// <param name="OPERATOR">操作人员</param>
        /// <returns></returns>
        [HttpPost("logOff")]
        public async Task<ActionResult> logOff(string NURSE_CODE, int TYPE , string OPERATOR)
        {
            var result = new Response<Responsedata>();

            try
            {
                var data = await _service.logOff(NURSE_CODE, TYPE, OPERATOR);

                result.code = 200;
                result.msg = "success";
                result.data = null;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }


        /// <summary>
        /// 4.2.1. 获取患者疾病诊断信息
        /// </summary>
        /// <param name="INP_NO">住院号</param>
        /// <param name="VISIT_ID">入院的次数</param>
        /// <param name="DEPT_CODE">科室编号</param>
        /// <param name="DIAGNOSE_TIME_FROM">诊断开始时间</param>
        /// <param name="DIAGNOSE_TIME_TO">诊断结束时间</param>
        /// <param name="INHOSPITAL">是否在院患者，1：是，0：否</param>
        /// <param name="PAGENUM">页码</param>
        /// <param name="PAGESIZE">每页显示条数</param>
        /// <returns></returns>
        [HttpGet("getDiagnose")]
        public async Task<ActionResult<ResponseList<Diagnose>>> getDiagnose(string? INP_NO,int? VISIT_ID,string? DEPT_CODE,DateTime? DIAGNOSE_TIME_FROM,DateTime? DIAGNOSE_TIME_TO, int? INHOSPITAL, int PAGENUM, int PAGESIZE)
        {
            var result = new ResponseList<Diagnose>();

            try
            {
                var data = await _service.getDiagnose(INP_NO, VISIT_ID, DEPT_CODE, DIAGNOSE_TIME_FROM, DIAGNOSE_TIME_TO, INHOSPITAL, PAGENUM, PAGESIZE);

                result.code = 200;
                result.msg = "success";
                result.data = data;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

        /// <summary>
        /// 4.3.1. 按日期查询患者 apache2 评分
        /// </summary>
        /// <param name="date">日期（yyyy-MM-dd）</param>
        /// <param name="pageNum">页码</param>
        /// <param name="pageSize">每页条数</param>
        /// <param name="hospitalId">医院编码</param>
        /// <param name="appKey">软件编码</param>
        /// <returns></returns>
        [HttpGet("patient/statistic/apache2Score")]
        public async Task<ActionResult> apache2Score(string date, int pageNum, int pageSize,string hospitalId, string appKey)
        {
            var result = new Response<Responsedata>();

            try
            {
                var data = await _service.apache2Score(date, pageNum, pageSize, hospitalId, appKey);

                result.code = 200;
                result.msg = "success";
                result.data = null;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }


        /// <summary>
        /// 4.3.2. 患者 apache2 评分
        /// </summary>
        /// <param name="date">日期（yyyy-MM-dd）</param>
        /// <param name="pageNum">页码</param>
        /// <param name="pageSize">每页条数</param>
        /// <param name="hospitalId">医院编码</param>
        /// <param name="appKey">软件编码</param>
        /// <returns></returns>
        [HttpGet("patient/statistic/apacheScore")]
        public async Task<ActionResult> apacheScore(string date, int pageNum, int pageSize, string hospitalId, string appKey)
        {
            var result = new Response<Responsedata>();

            try
            {
                var data = await _service.apacheScore(date, pageNum, pageSize, hospitalId, appKey);

                result.code = 200;
                result.msg = "success";
                result.data = null;
            }
            catch (Exception e)
            {

                _logger.LogError(e, "调用接口失败");

                result.code = -1;
                result.msg = e.Message;
            }

            return Content(JObject.FromObject(result).ToString(), "application/json", Encoding.UTF8);
        }

    }
}
